home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tools / anwender / gnuplot / demo / fit.dem < prev    next >
Encoding:
Text File  |  1995-11-25  |  5.6 KB  |  156 lines

  1. #
  2. # $Id: fit.dem,v 1.3 1995/04/06 14:01:53 drd Exp $
  3. #
  4.  
  5. pause 0 "Some examples how data fitting using nonlinear least squares fit"
  6. pause 0 "can be done."
  7. pause 0 ""
  8. pause -1 "first plotting the pure data set  (-> return)"
  9.  
  10. plot 'lcdemo.dat'
  11. set xlabel "Temperature T  [deg Cels.]"
  12. set ylabel "Density [g/cm3]"
  13.  
  14. pause 0 "now fitting a straight line to the data :-)"
  15. pause 0 "only as a demo without physical meaning"
  16. load 'line.fnc'
  17. y0 = 0.0
  18. m = 0.0
  19. show variables
  20. pause -1 "first a plot with all parameters set to zero  (-> return)"
  21. plot 'lcdemo.dat', l(x)
  22. pause -1 "now start fitting...  (-> return)"
  23. fit l(x) 'lcdemo.dat' via y0, m
  24. pause -1 "now look at the result (-> return)"
  25. plot 'lcdemo.dat', l(x)
  26.  
  27. pause -1 "see the influence of weights for single data points   (-> return)"
  28. fit l(x) 'lcdemo.dat' using 1:2:3 via y0, m
  29. pause -1 "now look at the result (-> return)"
  30. plot 'lcdemo.dat', l(x)
  31.  
  32. pause -1 "now prefer the high temperature data   (-> return)"
  33. fit l(x) 'lcdemo.dat' using 1:2:4 via y0, m
  34. pause -1 "now look at the result (-> return)"
  35. plot 'lcdemo.dat', l(x)
  36.  
  37. pause  0 "now use real single-measurement errors to reach such a result (-> return)"
  38. pause  0 "(look at the file lcdemo.dat and compare the columns to see the difference)"
  39. pause -1 "(-> return)"
  40. plot 'lcdemo.dat' using 1:2:5 with errorbars
  41. fit l(x) 'lcdemo.dat' using 1:2:5 via y0, m
  42. pause -1 "now look at the result (-> return)"
  43. plot 'lcdemo.dat' using 1:2:5 with errorbars, l(x)
  44.  
  45. pause 0 "It's time now to try a more realistic model function"
  46. load 'density.fnc'
  47. show functions
  48. pause 0 "density(x) is a function which shall fit the whole temperature"
  49. pause 0 "range using a ?: expression. It contains 6 model parameters which
  50. pause 0 "will all be varied. Now take the start parameters out of the"
  51. pause -1 "file 'start.par' and plot the function    (-> return)"
  52. load 'start.par'
  53. plot 'lcdemo.dat', density(x)
  54. fit density(x) 'lcdemo.dat' via 'start.par'
  55. pause -1 "now look at the result (-> return)"
  56. plot 'lcdemo.dat', density(x)
  57.  
  58. pause 0  "looks already rather nice? We will do now the following: set"
  59. pause 0  "the epsilon limit higher so that we need more iteration steps"
  60. pause 0  "to convergence. During fitting please hit ctrl-C. You will be asked"
  61. pause 0  "Stop, Continue, Execute: Try everything. You may define a script"
  62. pause 0  "using the FIT_SCRIPT environment variable. An example would be"
  63. pause 0  "'FIT_SCRIPT=plot nonsense.dat'. Normally you don't need to set"
  64. pause 0  "FIT_SCRIPT since it defaults to 'replot'. Please note that FIT_SCRIPT"
  65. pause 0  "cannot be set from inside gnuplot."
  66. pause 0  ""
  67. pause -1  "(-> return)"
  68. FIT_LIMIT = 1e-10
  69. fit density(x) 'lcdemo.dat' via 'start.par'
  70. pause -1 "now look at the result (-> return)"
  71. plot 'lcdemo.dat', density(x)
  72.  
  73. pause 0  ""
  74. pause 0  ""
  75. pause -1 "Now an example how to fit multi-branch functions  (-> return)"
  76. plot 'soundvel.dat'
  77. pause 0  "The model consists of two branches, the first describing longitudinal"
  78. pause 0  "sound velocity as function of propagation direction (upper data),"
  79. pause 0  "the second describing transverse sound velocity (lower data)."
  80. pause 0  ""
  81. pause 0  "The model uses these data in order to fit elastic stiffnesses"
  82. pause 0  "which occur differently in both branches."
  83. pause 0  ""
  84. pause -1 "(-> return)"
  85. load 'hexa.fnc'
  86. load 'sound.par'
  87. plot 'soundvel.dat', vlong(x), vtrans(x)
  88. fit f(x) 'soundvel.dat' via 'sound.par'
  89. pause 0  ""
  90. pause -1 "(-> return)"
  91. plot 'soundvel.dat', vlong(x), vtrans(x)
  92. pause 0  "Look at the file 'hexa.fnc' to see how the branches are realized"
  93. pause 0  "using the internal variable FIT_INDEX"
  94. pause 0  ""
  95. pause 0  "Next we only use every fifth data point for fitting by using the"
  96. pause 0  "'every' keyword. Look at the fitting-speed increase and at"
  97. pause 0  "fitting result."
  98. pause 0  ""
  99. pause -1 "(-> return)"
  100. load 'sound.par'
  101. plot 'soundvel.dat', vlong(x), vtrans(x)
  102. # FIT_SKIP = 4
  103. fit f(x) 'soundvel.dat' every 5 via 'sound.par'
  104. plot 'soundvel.dat', vlong(x), vtrans(x)
  105. pause 0  "When you compare the results (see 'fit.log') you remark that"
  106. pause 0  "the uncertainties in the fitted constants have become larger,"
  107. pause 0  "the quality of the plot is only slightly affected."
  108. pause 0  ""
  109. pause 0  "By marking some parameters as '# FIXED' in the parameter file"
  110. pause 0  "you fit only the others (c44 and c13 fixed here)."
  111. pause 0  ""
  112. pause -1 "(-> return)"
  113. load 'sound2.par'
  114. plot 'soundvel.dat', vlong(x), vtrans(x)
  115. fit f(x) 'soundvel.dat' via 'sound2.par'
  116. plot 'soundvel.dat', vlong(x), vtrans(x)
  117. pause 0  "This has the same effect as specifying only the real free"
  118. pause 0  "parameters by the 'via' syntax."
  119. pause 0  ""
  120. pause 0  "fit f(x) 'soundvel.dat' via c33, c11, phi0"
  121. pause 0  ""
  122. pause -1 "(-> return)"
  123. load 'sound.par'
  124. plot 'soundvel.dat', vlong(x), vtrans(x)
  125. fit f(x) 'soundvel.dat' via c33, c11, phi0
  126. plot 'soundvel.dat', vlong(x), vtrans(x)
  127.  
  128. pause 0  "Here comes an example of a very complex function..."
  129. pause 0  ""
  130. pause -1 "first plotting the pure data set  (-> return)"
  131.  
  132. set xlabel "Delta [degrees]"
  133. set ylabel "Reflectivity"
  134. plot 'moli3.dat'
  135.  
  136. pause 0 "now fitting the model function to the data"
  137. load 'reflect.fnc'
  138.  
  139. eta = 1.2e-2
  140. tc = 1.8e-3
  141.  
  142. show variables
  143. show functions
  144. pause -1 "first a plot with all parameters set to initial values  (-> return)"
  145. plot 'moli3.dat', R(x)
  146. pause -1 "now start fitting...  (-> return)"
  147. fit R(x) 'moli3.dat' via eta, tc
  148. pause -1 "now look at the result (-> return)"
  149. plot 'moli3.dat', R(x)
  150.  
  151. pause 0  "You can have a look at all previous fit results by looking into"
  152. pause 0  "the file 'fit.log' or whatever you defined the env-variable 'FIT_LOGFILE'."
  153. pause 0  "Remember that this file will always be appended, so remove it"
  154. pause 0  "from time to time!"
  155. pause 0  ""
  156.